package Composite;

import Visiteur.Visitable;
import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.io.*;
import java.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Observable;
import projetjava.Tags;

public abstract class Element extends Observable implements Transferable,Serializable,Visitable{
    
    private String nom;
    private String description;
    private Element pere;
    private File fichierCourant;
    final public static DataFlavor INFO_FLAVOR = new DataFlavor(Element.class, "Element Information");
    private static DataFlavor flavors[] = {INFO_FLAVOR };
    private Tags mesTags;
    
    public Element(String nom, Element pere,File fichierCourant) {
        
        this.nom=nom;
        this.pere=pere;
        this.fichierCourant=fichierCourant;
        this.mesTags = new Tags();
        
    }
    
    public Tags getTags(){
        
        return this.mesTags;
    }
    
    public  String getNom(){
        return this.nom;
    }
    
    public String toString(){
        return this.nom;
    }
    
    public String getDescription(){
        return this.description;
    }
    
    public File getFichierCourant(){
        
        return this.fichierCourant;
    }
    
    public Element getPere(){
        
        return this.pere;
    }
    
    public ArrayList getChildren(){
        throw new UnsupportedOperationException() ;
    }
    
    public boolean hasPere(){
        
        if(this.pere==null) return false;
        else return true;
    }
    
    public void setDescription(String description){
        
        this.description=description;
    }
    
    public void setNom(String nom){
        
        this.nom=nom;
        this.getPere().setChanged();
        this.getPere().notifyObservers(this);
        this.getPere().clearChanged();
    }
    
    public void addElement(Element e){
        throw new UnsupportedOperationException() ;
    }
    public void addElement(Element e,int index){
        throw new UnsupportedOperationException() ;
    }
    
    public void removeElement(Element e){
        throw new UnsupportedOperationException() ;
    }
    
    public Element  getChild(int index){
        throw new UnsupportedOperationException() ;
    }
    
    public int indexOf(Element child){
        throw new UnsupportedOperationException() ;
    }
    
    public int getChildCount(){
        throw new UnsupportedOperationException() ;
    }
    
    public Element getFile(String path){
        
        return this.getElementRecursif(path,null);
    }
    
    public String toStringReduit() {  // pour pas casser l'affichage jlistvignette
        if (this.nom.length() > 14) {
            return new String(this.nom.substring(0, 14) + "...");
        } else {
            return this.nom;
        }
    }
    
    public BufferedImage getApercu(String source) {
        
        throw new UnsupportedOperationException() ;
    }
    
    public abstract Element getElementRecursif(String path,Element retour);
    
    public boolean isDataFlavorSupported(DataFlavor df) {
        return df.equals(INFO_FLAVOR);
    }
    
    
    public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException {
        if (df.equals(INFO_FLAVOR)) {
            return this.getFichierCourant().getAbsolutePath();
        } else throw new UnsupportedFlavorException(df);
    }
    /** implements Transferable interface */
    public DataFlavor[] getTransferDataFlavors() {
        return flavors;
    }
    
    
    
}

















